home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_cpickle.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  105 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import cPickle
  5. import unittest
  6. from cStringIO import StringIO
  7. from pickletester import AbstractPickleTests, AbstractPickleModuleTests
  8. from test import test_support
  9.  
  10. class cPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
  11.     
  12.     def setUp(self):
  13.         self.dumps = cPickle.dumps
  14.         self.loads = cPickle.loads
  15.  
  16.     error = cPickle.BadPickleGet
  17.     module = cPickle
  18.  
  19.  
  20. class cPicklePicklerTests(AbstractPickleTests):
  21.     
  22.     def dumps(self, arg, proto = 0):
  23.         f = StringIO()
  24.         p = cPickle.Pickler(f, proto)
  25.         p.dump(arg)
  26.         f.seek(0)
  27.         return f.read()
  28.  
  29.     
  30.     def loads(self, buf):
  31.         f = StringIO(buf)
  32.         p = cPickle.Unpickler(f)
  33.         return p.load()
  34.  
  35.     error = cPickle.BadPickleGet
  36.  
  37.  
  38. class cPickleListPicklerTests(AbstractPickleTests):
  39.     
  40.     def dumps(self, arg, proto = 0):
  41.         p = cPickle.Pickler(proto)
  42.         p.dump(arg)
  43.         return p.getvalue()
  44.  
  45.     
  46.     def loads(self, *args):
  47.         f = StringIO(args[0])
  48.         p = cPickle.Unpickler(f)
  49.         return p.load()
  50.  
  51.     error = cPickle.BadPickleGet
  52.  
  53.  
  54. class cPickleFastPicklerTests(AbstractPickleTests):
  55.     
  56.     def dumps(self, arg, proto = 0):
  57.         f = StringIO()
  58.         p = cPickle.Pickler(f, proto)
  59.         p.fast = 1
  60.         p.dump(arg)
  61.         f.seek(0)
  62.         return f.read()
  63.  
  64.     
  65.     def loads(self, *args):
  66.         f = StringIO(args[0])
  67.         p = cPickle.Unpickler(f)
  68.         return p.load()
  69.  
  70.     error = cPickle.BadPickleGet
  71.     
  72.     def test_recursive_list(self):
  73.         self.assertRaises(ValueError, AbstractPickleTests.test_recursive_list, self)
  74.  
  75.     
  76.     def test_recursive_inst(self):
  77.         self.assertRaises(ValueError, AbstractPickleTests.test_recursive_inst, self)
  78.  
  79.     
  80.     def test_recursive_dict(self):
  81.         self.assertRaises(ValueError, AbstractPickleTests.test_recursive_dict, self)
  82.  
  83.     
  84.     def test_recursive_multi(self):
  85.         self.assertRaises(ValueError, AbstractPickleTests.test_recursive_multi, self)
  86.  
  87.     
  88.     def test_nonrecursive_deep(self):
  89.         a = []
  90.         for i in range(60):
  91.             a = [
  92.                 a]
  93.         
  94.         b = self.loads(self.dumps(a))
  95.         self.assertEqual(a, b)
  96.  
  97.  
  98.  
  99. def test_main():
  100.     test_support.run_unittest(cPickleTests, cPicklePicklerTests, cPickleListPicklerTests, cPickleFastPicklerTests)
  101.  
  102. if __name__ == '__main__':
  103.     test_main()
  104.  
  105.